home *** CD-ROM | disk | FTP | other *** search
/ Windows 95 API Bible / Windows 95 API Bible 3 Disc Set.iso / Win32 API Bible Book 3 of 3.iso / chapte11 / getvol / phone.c < prev    next >
C/C++ Source or Header  |  1996-04-28  |  22KB  |  649 lines

  1. #include <windows.h> 
  2. #include <windowsx.h> 
  3. #include "phone.h" 
  4. #include "tapi.h"
  5.  
  6. #define BUFSIZE 256
  7. #define APIHIVERSION     0x00010028    /* 1.40 */
  8. #define APILOWVERSION    0x00010000    /* 1.0 */
  9. #define EXTHIVERSION     0x00010005    /* 1.5 */
  10. #define EXTLOWVERSION    0x00000009    /* 0.9 */ 
  11. #define MAX_PHONE        2
  12. #define OWNER            0
  13. #define MONITOR        1
  14.  
  15. LPCTSTR lpszAppName = "phoneGetVolume";
  16. LPCTSTR lpszTitle   = "phoneGetVolume";
  17.  
  18.  
  19. #if defined (WIN32)
  20.     #define IS_WIN32 TRUE
  21. #else
  22.     #define IS_WIN32 FALSE
  23. #endif
  24.  
  25. #define IS_NT      IS_WIN32 && (BOOL)(GetVersion() < 0x80000000)
  26. #define IS_WIN32S  IS_WIN32 && (BOOL)(!(IS_NT) && (LOBYTE(LOWORD(GetVersion()))<4))
  27. #define IS_WIN95   (BOOL)(!(IS_NT) && !(IS_WIN32S)) && IS_WIN32
  28.  
  29. HINSTANCE hInst;   // current instance
  30. HWND hWnd;         // parent window handle
  31. HWND hListWnd;     // listbox
  32. HDC  hdc;
  33. TEXTMETRIC  tm ;
  34.  
  35. BOOL RegisterWin95( CONST WNDCLASS* lpwc );
  36.  
  37.  
  38. int APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
  39.                       LPTSTR lpCmdLine, int nCmdShow)
  40. {
  41.    MSG      msg;
  42.    WNDCLASS wc;
  43.  
  44.    wc.style         = CS_HREDRAW | CS_VREDRAW;
  45.    wc.lpfnWndProc   = (WNDPROC)WndProc;       
  46.    wc.cbClsExtra    = 0;                      
  47.    wc.cbWndExtra    = 0;                      
  48.    wc.hInstance     = hInstance;              
  49.    wc.hIcon         = LoadIcon (hInstance, lpszAppName); 
  50.    wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
  51.    wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
  52.    wc.lpszMenuName  = lpszAppName;              
  53.    wc.lpszClassName = lpszAppName;              
  54.  
  55.    if ( IS_WIN95 )
  56.    {
  57.       if ( !RegisterWin95( &wc ) )
  58.          return( FALSE );
  59.    }
  60.    else if ( !RegisterClass( &wc ) )
  61.       return( FALSE );
  62.  
  63.    hInst = hInstance; 
  64.  
  65.    hWnd = CreateWindow( lpszAppName, 
  66.                         lpszTitle,    
  67.                         WS_OVERLAPPEDWINDOW, 
  68.                         CW_USEDEFAULT, 0, 
  69.                         CW_USEDEFAULT, 0,  
  70.                         NULL,              
  71.                         NULL,              
  72.                         hInstance,         
  73.                         NULL               
  74.                       );
  75.  
  76.    if ( !hWnd ) 
  77.       return( FALSE );
  78.  
  79.    ShowWindow( hWnd, nCmdShow ); 
  80.    UpdateWindow( hWnd );         
  81.  
  82.    while( GetMessage( &msg, NULL, 0, 0) )   
  83.    {
  84.       TranslateMessage( &msg ); 
  85.       DispatchMessage( &msg );  
  86.    }
  87.  
  88.    return( msg.wParam ); 
  89. }
  90.  
  91.  
  92. BOOL RegisterWin95( CONST WNDCLASS* lpwc )
  93. {
  94.     WNDCLASSEX wcex;
  95.  
  96.    wcex.style         = lpwc->style;
  97.    wcex.lpfnWndProc   = lpwc->lpfnWndProc;
  98.    wcex.cbClsExtra    = lpwc->cbClsExtra;
  99.    wcex.cbWndExtra    = lpwc->cbWndExtra;
  100.    wcex.hInstance     = lpwc->hInstance;
  101.    wcex.hIcon         = lpwc->hIcon;
  102.    wcex.hCursor       = lpwc->hCursor;
  103.    wcex.hbrBackground = lpwc->hbrBackground;
  104.    wcex.lpszMenuName  = lpwc->lpszMenuName;
  105.    wcex.lpszClassName = lpwc->lpszClassName;
  106.  
  107.    // Added elements for Windows 95.
  108.    //...............................
  109.    wcex.cbSize = sizeof(WNDCLASSEX);
  110.    wcex.hIconSm = LoadImage(wcex.hInstance, lpwc->lpszClassName, 
  111.                             IMAGE_ICON, 16, 16,
  112.                             LR_DEFAULTCOLOR );
  113.             
  114.    return RegisterClassEx( &wcex );
  115. }
  116.  
  117. typedef struct tagMYINFO    // general application information
  118. {
  119.    HPHONEAPP phoneApp;      // instance handle TAPI gives back to us                                                                              through phoneInitialize()
  120.    DWORD dwNumDevices;     // number of available devices
  121.    DWORD dwAPIVersion;     // API version the phone supports
  122.     DWORD dwExtVersion;        // extended version
  123. } MYINFO;
  124.  
  125. typedef struct tagPHONEINFO  // information on an open phone
  126. {
  127.    HPHONE     hPhone;           // handle to the phone as returned by phoneOpen 
  128.     DWORD      dwDeviceID;            // device ID of the phone device
  129.     DWORD        dwRequestID;
  130.     char       szPhoneName[128]; // the phone's name 
  131. }PHONEINFO;
  132.  
  133. MYINFO myInfo;          //instance of MYINFO structure
  134. PHONEINFO myPhoneInfo[MAX_PHONE];  //instance of myPhoneInfo structure
  135.  
  136. LONG lRet;        //return code
  137. char buf[BUFSIZE];    // buffer for debug message
  138. char DataBuf[BUFSIZE]; //get/set data buffer;
  139.  
  140. DWORD i;
  141. DWORD dwHookSwitchDevs;
  142. DWORD dwLampMode;
  143. DWORD dwRingMode;
  144. DWORD dwRingVolume;
  145. DWORD dwHookSwitchVolume;
  146. DWORD dwPhoneStates;
  147. DWORD dwButtonModes;
  148. DWORD dwButtonStates;
  149. DWORD dwGain;
  150. HICON hIcon;
  151.  
  152. LONG lRet;
  153. char buf[BUFSIZE];
  154.  
  155. PHONECAPS*             pPhoneCaps;
  156. PHONEBUTTONINFO*  pButtonInfo;
  157. VARSTRING*            pVarString;
  158. PHONESTATUS*        pPhoneStatus;
  159. PHONEEXTENSIONID    ext_id;                                             
  160.  
  161.  
  162. LRESULT CALLBACK WndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
  163. {
  164.    switch( uMsg )
  165.    {
  166.       case WM_COMMAND :
  167.          switch( LOWORD( wParam ) )
  168.          {
  169.             case IDM_RUN :
  170.                pPhoneCaps = (PHONECAPS *) calloc (1, sizeof(PHONECAPS)+1000);
  171.                    pPhoneCaps->dwTotalSize = sizeof(PHONECAPS) + 1000;
  172.                          
  173.                    phoneGetDevCaps(myInfo.phoneApp,OWNER,
  174.                            myInfo.dwAPIVersion, myInfo.dwExtVersion, pPhoneCaps);
  175.                
  176.                if (pPhoneCaps->dwVolumeFlags & PHONEHOOKSWITCHDEV_SPEAKER)
  177.                     {
  178.                    lRet = phoneGetVolume(myPhoneInfo[OWNER].hPhone, PHONEHOOKSWITCHDEV_SPEAKER, &dwHookSwitchVolume);
  179.                      if (lRet == 0)
  180.                      {
  181.                       wsprintf(buf, "phoneGetVolume succeeded!");
  182.                          SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  183.                      wsprintf(buf, "The hookswitch volume for the speaker device is x%lx", dwHookSwitchVolume);
  184.                          SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  185.                   }
  186.                        else 
  187.                      {
  188.                           wsprintf( buf,"phoneGetVolume failed, err=x%lx", lRet);
  189.                          phoneError(lRet);
  190.                      break;
  191.                      }    
  192.                    
  193.                   if (dwHookSwitchVolume < 0x0000CCCC)
  194.                   {
  195.                      wsprintf(buf, "The current volume is less than 80%, setting volume!");
  196.                           SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  197.                       lRet = phoneSetVolume(myPhoneInfo[OWNER].hPhone, PHONEHOOKSWITCHDEV_SPEAKER, 25);
  198.                           if (lRet > 0)
  199.                          {
  200.                          myPhoneInfo[OWNER].dwRequestID = lRet;
  201.                          wsprintf(buf, "phoneSetVolume proceeding!");
  202.                              SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  203.                          }
  204.                            else 
  205.                          {
  206.                              wsprintf( buf,"phoneSetVolume failed, err=x%lx", lRet);
  207.                              phoneError(lRet);
  208.                             SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  209.                          }    
  210.                        }
  211.                }
  212.                     else
  213.                     {
  214.                         wsprintf( buf,"The phone does not have the capability to set the volume.");
  215.                         SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  216.                       phoneError(lRet);
  217.                     }
  218.                    
  219.                    free (pPhoneCaps);
  220.                break;
  221.                     
  222.             case IDM_EXIT :
  223.                for (i = 0; i < myInfo.dwNumDevices; i++)
  224.                     phoneClose(myPhoneInfo[i].hPhone);
  225.                 
  226.                    phoneShutdown(myInfo.phoneApp);
  227.                DestroyWindow( hWnd );
  228.                break;
  229.          
  230.             case IDM_ABOUT :
  231.                 DialogBox( hInst, "AboutBox", hWnd, (DLGPROC)About );
  232.                break;
  233.          }
  234.                 
  235.             return( DefWindowProc( hWnd, uMsg, wParam, lParam ) );
  236.  
  237.       
  238.        case WM_CREATE :
  239.  
  240.           hdc = GetDC (hWnd) ;
  241.           GetTextMetrics (hdc, &tm) ;
  242.           ReleaseDC (hWnd, hdc) ;
  243.  
  244.           hListWnd = CreateWindowEx( 0, "listbox", 
  245.                         " ",    
  246.                         WS_CHILD | WS_VISIBLE,  
  247.                         tm.tmAveCharWidth, tm.tmHeight * 3, 
  248.                         tm.tmAveCharWidth * 16 +
  249.                                    GetSystemMetrics (SM_CXVSCROLL), 
  250.                         tm.tmHeight * 5,  
  251.                         hWnd,              
  252.                         NULL,              
  253.                         hInst,         
  254.                         NULL               
  255.                         );
  256.       
  257.              //phoneInitialize
  258.                //...............................................
  259.             lRet = phoneInitialize(&myInfo.phoneApp, hInst, phoneCallback, lpszAppName, &myInfo.dwNumDevices);
  260.             if (lRet == 0) 
  261.             {
  262.                 
  263.                wsprintf(buf, "phoneInitialize succeeded!");
  264.                    SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  265.             }
  266.                
  267.                else 
  268.                {
  269.                    wsprintf( buf,"phoneInitialize failed, err=x%lx",lRet);
  270.                SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  271.                     phoneError(lRet);
  272.                     break;
  273.             }                    
  274.                
  275.             //phoneNegotiateAPIVersion
  276.                   //...............................................
  277.             lRet = phoneNegotiateAPIVersion(myInfo.phoneApp, 0, APILOWVERSION, APIHIVERSION, 
  278.                                                     &myInfo.dwAPIVersion, &ext_id);
  279.             if (lRet == 0)                        
  280.             {
  281.                wsprintf(buf, "phoneNegotiateAPIVersion succeeded!");
  282.                       SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  283.             }
  284.                   else 
  285.                   {
  286.                    wsprintf(buf, "phoneNegotiateAPIVersion failed, err=x%lx", lRet);
  287.                     SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  288.                     phoneError(lRet);
  289.                     phoneShutdown(myInfo.phoneApp);
  290.                break;
  291.              }
  292.  
  293.                //phoneNegotiateExtVersion
  294.                //...............................................
  295.             lRet = phoneNegotiateExtVersion(myInfo.phoneApp, 0, myInfo.dwAPIVersion, EXTLOWVERSION, 
  296.                                                 EXTHIVERSION, &myInfo.dwExtVersion);
  297.             if (lRet == 0)                        
  298.             {
  299.                     wsprintf(buf, "phoneNegotiateExtVersion succeeded!");
  300.                SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  301.               }
  302.                   else 
  303.                {
  304.                     wsprintf(buf, "phoneNegotiateExtVersion failed, err=x%lx", lRet);
  305.                       SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  306.                       phoneError(lRet);
  307.                }
  308.  
  309.             //phoneOpen
  310.                //................................................................
  311.                for (i = 0; i < myInfo.dwNumDevices; i++)
  312.                {
  313.                    if ( i == 0)
  314.                        lRet = phoneOpen(myInfo.phoneApp,i,&myPhoneInfo[i].hPhone,
  315.                                  myInfo.dwAPIVersion,0,(DWORD)phoneCallback, PHONEPRIVILEGE_OWNER);
  316.                    else
  317.                        lRet = phoneOpen(myInfo.phoneApp,i,&myPhoneInfo[i].hPhone,
  318.                                  myInfo.dwAPIVersion,0,(DWORD)phoneCallback, PHONEPRIVILEGE_MONITOR);
  319.                    
  320.                    if (lRet == 0)
  321.                    {
  322.                      wsprintf(buf, "phoneOpen succeeded!");
  323.                         SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  324.                   pPhoneCaps = (PHONECAPS *) calloc (1, sizeof(PHONECAPS)+1000);
  325.                       pPhoneCaps->dwTotalSize = sizeof(PHONECAPS) + 1000;
  326.                          
  327.                       phoneGetDevCaps(myInfo.phoneApp,i,
  328.                       myInfo.dwAPIVersion, myInfo.dwExtVersion, pPhoneCaps);
  329.                       strcpy(buf, ((LPSTR)(pPhoneCaps)+pPhoneCaps->dwProviderInfoOffset));
  330.                   strcat( buf, " is the phone providor's name." );
  331.                   SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  332.                   strcpy(buf, ((LPSTR)(pPhoneCaps)+pPhoneCaps->dwPhoneNameOffset));
  333.                      
  334.                   if (i == 0)
  335.                   {
  336.                      strcat( buf, " is the phone's name opened with OWNER privilege." );
  337.                      SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  338.                   }
  339.                   else
  340.                   {
  341.                      strcat( buf, " is the phone's name opened with MONITOR privilege." );
  342.                      SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  343.                   }
  344.                }
  345.                    else 
  346.                    {
  347.                        wsprintf( buf,"phoneOpen failed, err=x%lx", lRet);
  348.                        phoneError(lRet);
  349.                       break;
  350.                }
  351.                   } 
  352.  
  353.             break;
  354.       
  355.       case WM_SIZE:
  356.           MoveWindow(hListWnd, 0, 0, LOWORD(lParam), HIWORD(lParam), TRUE);
  357.          break;
  358.  
  359.       case WM_DESTROY :
  360.          PostQuitMessage(0);
  361.          break;
  362.             
  363.       default :
  364.             return( DefWindowProc( hWnd, uMsg, wParam, lParam ) );
  365.    }
  366.  
  367.    return( 0L );
  368. }
  369.  
  370.  
  371.  
  372. /****************************************************************************
  373.     FUNCTION: phoneCallback
  374.     PURPOSE:  callback function handles phone events
  375. ****************************************************************************/
  376. LRESULT CALLBACK phoneCallback (DWORD  dwDevice, DWORD dwMsg,
  377.                                 DWORD dwCallbackInst, DWORD dwParam1,
  378.                                 DWORD dwParam2,DWORD dwParam3)
  379. {
  380.     
  381.     switch (dwMsg)
  382.     {
  383.         case PHONE_REPLY:
  384.             if (dwParam1 == myPhoneInfo[OWNER].dwRequestID) 
  385.                    if (dwParam2 != 0)
  386.                 {
  387.                        wsprintf( buf,"Function failed, err=x%lx", lRet);
  388.                        phoneError(lRet);
  389.                     SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  390.                    }
  391.             break;       
  392.  
  393.         case PHONE_STATE:
  394.         
  395.             if (dwParam1 == PHONESTATE_RINGMODE)
  396.             {
  397.                 lRet = phoneGetRing(myPhoneInfo[OWNER].hPhone, &dwRingMode, &dwRingVolume);
  398.                 if (lRet == 0)
  399.                {
  400.                 wsprintf(buf, "phoneGetRing succeeded!");
  401.                    SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  402.                if (dwRingMode == 0)
  403.                     {
  404.                         wsprintf(buf, "The phone device is currently not ringing.");
  405.                         SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  406.                }
  407.                     else
  408.                     {
  409.                         wsprintf(buf, "The phone is ringing with a Ring Mode pattern of x%lx", dwRingMode);
  410.                         SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  411.                    wsprintf(buf, "The phnes's Ring Volume is x%lx", dwRingVolume);
  412.                         SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  413.                     }
  414.                }
  415.                  else 
  416.                {
  417.                     wsprintf( buf,"phoneGetRing failed, err=x%lx", lRet);
  418.                    phoneError(lRet);
  419.                }        
  420.               
  421.               break;
  422.               }
  423.             
  424.  
  425.             if (dwParam1 == PHONESTATE_SPEAKERHOOKSWITCH)
  426.             {   
  427.                 lRet = phoneGetHookSwitch(myPhoneInfo[OWNER].hPhone, &dwHookSwitchDevs);
  428.                 if (lRet == 0)
  429.                {
  430.                wsprintf(buf, "phoneGetHookSwitch succeeded!");
  431.                       SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  432.                
  433.                if (dwHookSwitchDevs & PHONEHOOKSWITCHDEV_SPEAKER)
  434.                     {
  435.                         wsprintf(buf, "The phone's HookSwitch Speaker is offhook!");
  436.                        SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  437.                     }
  438.                     else
  439.                     {
  440.                    wsprintf(buf, "The phone's HookSwitch Speaker is onhook!");
  441.                         SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  442.                     }
  443.  
  444.               }
  445.                  else 
  446.                {
  447.                       wsprintf( buf,"phoneGetHookSwitch failed, err=x%lx", lRet);
  448.                    phoneError(lRet);
  449.                }    
  450.             break;                
  451.             }
  452.  
  453.             if (dwParam1 == PHONESTATE_SPEAKERVOLUME)
  454.             {   
  455.                 lRet = phoneGetVolume(myPhoneInfo[OWNER].hPhone, PHONEHOOKSWITCHDEV_SPEAKER, &dwHookSwitchVolume);
  456.                if (lRet == 0)
  457.                {
  458.                 wsprintf(buf, "phoneGetVolume succeeded!");
  459.                    SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  460.                wsprintf(buf, "The current volume for the Speaker Hookswitch is x%lx", dwHookSwitchVolume);
  461.                     SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  462.                }
  463.                  else 
  464.                {
  465.                     wsprintf( buf,"phoneGetVolume failed, err=x%lx", lRet);
  466.                    phoneError(lRet);
  467.                }    
  468.             break;                
  469.             }
  470.  
  471.             if (dwParam1 == PHONESTATE_SPEAKERGAIN)
  472.             {   
  473.                 lRet = phoneGetGain(myPhoneInfo[OWNER].hPhone, PHONEHOOKSWITCHDEV_SPEAKER, &dwGain);
  474.                 if (lRet == 0)
  475.                {
  476.                   wsprintf(buf, "phoneGetGain succeeded!");
  477.                       SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  478.                     wsprintf(buf, "The current Gain is x%lx", dwGain);
  479.                     SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  480.                }
  481.                  else 
  482.                {
  483.                       wsprintf( buf,"phoneGetGain failed, err=x%lx", lRet);
  484.                     phoneError(lRet);
  485.                }
  486.             break;                
  487.             }
  488.             
  489.             if (dwParam1 == PHONESTATE_DISPLAY)
  490.             {   
  491.                 pVarString = (VARSTRING *) calloc (1, sizeof(VARSTRING)+1000);
  492.                 pVarString->dwTotalSize = sizeof(VARSTRING) + 1000;
  493.                 lRet = phoneGetDisplay(myPhoneInfo[OWNER].hPhone, pVarString);
  494.                 if (lRet == 0)
  495.                {
  496.                   wsprintf(buf, "phoneGetDisplay succeeded!");
  497.                       SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  498.                strcpy(buf, lpszTitle);
  499.                //strcpy(buf, ((LPSTR)(pVarString)+pVarString->dwStringOffset));
  500.                strcat( buf, " is the current phone display." );
  501.                SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  502.                }
  503.                  else 
  504.                {
  505.                    wsprintf( buf,"phoneGetDisplay failed, err=x%lx", lRet);
  506.                   phoneError(lRet);
  507.                }    
  508.                     
  509.                 free (pVarString);
  510.                 break;
  511.               }
  512.    }
  513.    return (TRUE);
  514.  
  515.  
  516. /****************************************************************************
  517.     FUNCTION: phoneError
  518.     PURPOSE:  phone error messages
  519. ****************************************************************************/
  520. void phoneError (LONG lrc)
  521. {
  522.  switch (lrc) {
  523.     case PHONEERR_INVALAPPHANDLE:
  524.        MessageBox (hWnd, "Invalid app handle.", "", MB_OK);
  525.        break;
  526.     case PHONEERR_BADDEVICEID:
  527.        MessageBox (hWnd,"The specified phone device ID is out of range.", "", 
  528.                    MB_OK);
  529.        break;
  530.     case PHONEERR_INCOMPATIBLEAPIVERSION:
  531.        MessageBox (hWnd, "Incompatible API version.", "", MB_OK);
  532.        break;
  533.     
  534.     case PHONEERR_INVALBUTTONLAMPID:
  535.        MessageBox (hWnd, "Invalid Button Lamp ID.", "", MB_OK);
  536.        break;
  537.  
  538.     case PHONEERR_INVALBUTTONMODE:
  539.        MessageBox (hWnd, "Invalid Button Mode.", "", MB_OK);
  540.        break;
  541.  
  542.     case PHONEERR_INVALBUTTONSTATE:
  543.        MessageBox (hWnd, "Invalid Button State", "", MB_OK);
  544.        break;
  545.  
  546.     case PHONEERR_INUSE:
  547.        MessageBox (hWnd, "Phone in Use.", "", MB_OK);
  548.        break;
  549.     
  550.     case PHONEERR_INVALHOOKSWITCHDEV:
  551.        MessageBox (hWnd, "Invalid Hookswitch Device.", "", MB_OK);
  552.        break;
  553.  
  554.     case PHONEERR_INVALHOOKSWITCHMODE:
  555.        MessageBox (hWnd, "Invalid Hookswitch Device Mode.", "", MB_OK);
  556.        break;
  557.  
  558.     case PHONEERR_INVALLAMPMODE:
  559.        MessageBox (hWnd, "Invalid Lamp Mode.", "", MB_OK);
  560.        break;
  561.      
  562.     case PHONEERR_INCOMPATIBLEEXTVERSION:
  563.        MessageBox (hWnd, "Incompatible extension version.","", MB_OK);
  564.        break;
  565.     case PHONEERR_NOMEM:
  566.        MessageBox (hWnd, "No memory","", MB_OK);
  567.        break;
  568.     case PHONEERR_NODRIVER:
  569.        MessageBox (hWnd, "No driver loaded", "", MB_OK);
  570.        break;
  571.     case PHONEERR_RESOURCEUNAVAIL:
  572.        MessageBox (hWnd, "Resource overcommittment", "", MB_OK);
  573.        break;
  574.     case PHONEERR_ALLOCATED:
  575.        MessageBox (hWnd, "Allocation error", "", MB_OK);
  576.        break;
  577.     case PHONEERR_INVALDATAID:
  578.        MessageBox (hWnd, "The data ID is out of range.", "", MB_OK);
  579.        break;
  580.     case PHONEERR_INVALDEVICECLASS:
  581.        MessageBox (hWnd, "The device class was invalid.", "", MB_OK);
  582.        break;
  583.     case PHONEERR_INVALPOINTER:
  584.        MessageBox (hWnd, "The specified pointer parameter is invalid.",
  585.                    "", MB_OK);
  586.        break;
  587.     case PHONEERR_OPERATIONFAILED:
  588.        MessageBox (hWnd, "Operation failed.", "", MB_OK);
  589.        break;
  590.     case PHONEERR_INVALPHONEHANDLE:
  591.        MessageBox (hWnd, "Invalid phone handle", "", MB_OK);
  592.        break;
  593.     case PHONEERR_INVALPHONESTATE :
  594.        MessageBox (hWnd, "Invalid call state for this function.", "", MB_OK);
  595.        break;
  596.     case PHONEERR_INVALPRIVILEGE:
  597.        MessageBox (hWnd, "Invalid privilege for this function.", "", MB_OK);
  598.        break;
  599.     case PHONEERR_NODEVICE:
  600.        MessageBox (hWnd, "No associated device for given class",
  601.                    "", MB_OK);
  602.        break;
  603.     case PHONEERR_OPERATIONUNAVAIL:
  604.        MessageBox (hWnd, "The operation is unavailable",
  605.                    "", MB_OK);
  606.        break;
  607.     case PHONEERR_INVALPARAM:
  608.         MessageBox(hWnd, "Invalid Paramater", "", MB_OK);
  609.        break; 
  610.  
  611.     case PHONEERR_INVALRINGMODE:
  612.             MessageBox(hWnd, "Invalid Ring Mode", "", MB_OK);
  613.        break; 
  614.  
  615.     }
  616.     
  617.              
  618. }
  619.  
  620. LRESULT CALLBACK About( HWND hDlg,           
  621.                         UINT message,        
  622.                         WPARAM wParam,       
  623.                         LPARAM lParam)
  624. {
  625.    switch (message) 
  626.    {
  627.        case WM_INITDIALOG: 
  628.                return (TRUE);
  629.  
  630.        case WM_COMMAND:                              
  631.                if (   LOWORD(wParam) == IDOK         
  632.                    || LOWORD(wParam) == IDCANCEL)    
  633.                {
  634.                        EndDialog(hDlg, TRUE);        
  635.                        return (TRUE);
  636.                }
  637.                break;
  638.    }
  639.  
  640.    return (FALSE); 
  641. }
  642.  
  643.  
  644.  
  645.  
  646.  
  647.  
  648.